package WordCount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author 姜世钰
 * date: 2021/9/29 15:35
 **/
public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    @Override   //Context上下文用于输出
    protected void map(LongWritable key1,Text value1,Context context) throws IOException, InterruptedException {
        String data = value1.toString();//数据

        String[] words = data.split(" ");//分词：按空格来分词

        for (String word : words) {
           context.write(new Text(word),new IntWritable(1));
        }

    }
}
